//
//  LGBallDetailOperatPlanCell.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2023/8/25.
//  入院计划

#import "LGBallDetailOperatPlanCell.h"

#define lineHeight  viewPix(33)

#define lineTop     viewPix(42)

@interface LGBallDetailOperatPlanCell()
/**   */
@property (nonatomic , strong)UIView *baseView;
/**   */
@property (nonatomic , strong)UILabel *statusLabel;
/**   */
@property (nonatomic , strong)UIView *lineView;
/**   */
@property (nonatomic , strong)UILabel *planTitle;
/**   */
@property (nonatomic , strong)UILabel *planLabel;
/**   */
@property (nonatomic , strong)UILabel *inspectTitle;
/**   */
@property (nonatomic , strong)UILabel *inspectLabel;
/**   */
@property (nonatomic , strong)UILabel *remarkTitle;
/**   */
@property (nonatomic , strong)UILabel *remarkLabel;
@end

@implementation LGBallDetailOperatPlanCell
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubView];
    }
    return  self;
}

-(void)setDataDic:(NSDictionary *)dataDic{
    _dataDic = dataDic;
    //-1|未上传已过期 、0|未上传 、1|已上传 、2|已忽略
    NSString *status = LGNSString(dataDic[@"reportup_status"]);
    if([status isEqualToString:@"-1"]){
        //未上传（已过计划时间)-红色
        self.statusLabel.text = @"未上传";
        self.statusLabel.textColor = [UIColor colorWithString:@"#DD3030"];
        
    }else if ([status isEqualToString:@"0"]){
        //未完成-已过期-蓝色
        self.statusLabel.text = @"未上传";
        self.statusLabel.textColor = [UIColor colorWithString:@"#3291FF"];
        
    }else if ([status isEqualToString:@"1"]){
        //已上传
        self.statusLabel.text = @"已上传";
        self.statusLabel.textColor = [UIColor colorWithString:@"#999999"];
        
    }else{
        //已忽略
        NSString *reason = [LGNSString(dataDic[@"omit_reason"]) isEmptyString]?@"":[NSString stringWithFormat:@"（%@）",dataDic[@"omit_reason"]];
        self.statusLabel.text = [NSString stringWithFormat:@"已忽略%@",reason];
        self.statusLabel.textColor = [UIColor colorWithString:@"#999999"];
    }
    self.planLabel.text = LGNSString(dataDic[@"task_date"]);
    
    NSArray *inspectArray = dataDic[@"task_inspections"];
    NSString *inspect = @"";
    for (NSString *content in inspectArray) {
        inspect = (inspect.length>0)?[NSString stringWithFormat:@"%@、%@",inspect,content]:content;
    }
    CGFloat inspectTop = [inspect isEmptyString]?0:viewPix(10);
    self.inspectTitle.hidden = [inspect isEmptyString]?YES:NO;
    self.inspectLabel.text = inspect;
    [self.inspectTitle mas_updateConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.planTitle.mas_bottom).offset(inspectTop);
    }];
    
    
    NSString *remark = [LGNSString(dataDic[@"task_remark"]) isEmptyString]?@"":LGNSString(dataDic[@"task_remark"]);
    self.remarkLabel.text = remark;
    self.remarkTitle.hidden = [remark isEmptyString]?YES:NO;
    CGFloat remarkTop = [remark isEmptyString]?0:viewPix(10);
    [self.remarkTitle mas_updateConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.inspectLabel.mas_bottom).offset(remarkTop);
    }];
}



-(void)createSubView{
    self.contentView.backgroundColor = [UIColor colorWithString:@"#F2F3F5"];
    [self.contentView addSubview:self.baseView];
    [self.baseView addSubview:self.statusLabel];
    [self.baseView addSubview:self.lineView];
    [self.baseView addSubview:self.planTitle];
    [self.baseView addSubview:self.planLabel];
    [self.baseView addSubview:self.inspectTitle];
    [self.baseView addSubview:self.inspectLabel];
    [self.baseView addSubview:self.remarkTitle];
    [self.baseView addSubview:self.remarkLabel];
    [self.baseView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView);
        make.left.equalTo(self.contentView).offset(viewPix(16));
        make.right.equalTo(self.contentView).offset(-viewPix(16));
        make.bottom.equalTo(self.contentView).offset(-viewPix(8));
    }];
    [self.statusLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.equalTo(self.baseView).offset(viewPix(12));
        make.right.equalTo(self.baseView).offset(-viewPix(12));
    }];
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.statusLabel.mas_bottom).offset(viewPix(10));
        make.left.right.equalTo(self.statusLabel);
        make.height.equalTo(@(0.5));
    }];
    [self.planTitle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.lineView.mas_bottom).offset(viewPix(10));
        make.left.equalTo(self.statusLabel);
        make.width.equalTo(@(viewPix(60)));
    }];
    [self.planLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.baseView).offset(-viewPix(12));
        make.centerY.equalTo(self.planTitle);
    }];
    [self.inspectTitle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.planTitle.mas_bottom).offset(viewPix(10));
        make.left.width.equalTo(self.planTitle);
    }];
    [self.inspectLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.baseView).offset(-viewPix(12));
        make.left.equalTo(self.inspectTitle.mas_right).offset(viewPix(10));
        make.top.equalTo(self.inspectTitle);
    }];
    [self.remarkTitle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.inspectLabel.mas_bottom).offset(viewPix(10));
        make.left.equalTo(self.planTitle);
    }];
    [self.remarkLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.remarkTitle.mas_right).offset(viewPix(10));
        make.right.equalTo(self.baseView).offset(-viewPix(12));
        make.top.equalTo(self.remarkTitle);
        make.bottom.equalTo(self.baseView).offset(-viewPix(12));
    }];
}

-(UIView *)baseView{
    if(!_baseView){
        _baseView = [UIView shadowViewWithColor:@"#B3C5D9" offset:CGSizeMake(0, 2) opacity:0.15 radius:15];
        _baseView.backgroundColor = [UIColor whiteColor];
    }
    return _baseView;
}

-(UILabel *)statusLabel{
    if(!_statusLabel){
        _statusLabel = [UILabel lableWithText:@"" colorString:@"#999999" textFont:LGFontWeight(14, UIFontWeightMedium) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _statusLabel;
}

-(UIView *)lineView{
    if(!_lineView){
        _lineView = [[UIView alloc]initWithFrame:CGRectMake(viewPix(12), viewPix(40), Screen_W-viewPix(56), 0.5)];
        _lineView.backgroundColor = [UIColor colorWithString:@"#E0E0E0"];
    }
    return _lineView;
}

-(UILabel *)planTitle{
    if(!_planTitle){
        _planTitle = [UILabel lableWithText:@"计划时间" colorString:@"#666666" textFont:LGFont(14) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _planTitle;
}

-(UILabel *)planLabel{
    if(!_planLabel){
        _planLabel = [UILabel lableWithText:@"" colorString:@"#333333" textFont:LGFont(14) textAlignment:NSTextAlignmentRight lines:1];
    }
    return _planLabel;
}
-(UILabel *)inspectTitle{
    if(!_inspectTitle){
        _inspectTitle = [UILabel lableWithText:@"检查项目" colorString:@"#666666" textFont:LGFont(14) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _inspectTitle;
}
-(UILabel *)inspectLabel{
    if(!_inspectLabel){
        _inspectLabel = [UILabel lableWithText:@"" colorString:@"#333333" textFont:LGFont(14) textAlignment:NSTextAlignmentRight lines:0];
    }
    return _inspectLabel;
}

-(UILabel *)remarkTitle{
    if(!_remarkTitle){
        _remarkTitle = [UILabel lableWithText:@"备注" colorString:@"#333333" textFont:LGFontWeight(14, UIFontWeightMedium) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _remarkTitle;
}

-(UILabel *)remarkLabel{
    if(!_remarkLabel){
        _remarkLabel = [UILabel lableWithText:@"" colorString:@"#666666" textFont:LGFont(14) textAlignment:NSTextAlignmentRight lines:0];
    }
    return _remarkLabel;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
